package com.zoweunion.mechanic.netty;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

@Component
public class ChildChannelHandler extends ChannelInitializer<SocketChannel> {
	
    @Resource
    private DiscardServerHandler discardServerHandler;
    
    @Override
    public void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast(discardServerHandler);
        socketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024));
        socketChannel.pipeline().addLast(new StringDecoder());
        //以"$_"作为分隔符
//        socketChannel.pipeline().addLast("encoder", (ChannelHandler) new StringEncoder(CharsetUtil.UTF_8));
//        String s = "$_";
//        ByteBuf byteBuf = Unpooled.copiedBuffer(s.getBytes());
//        socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(Integer.MAX_VALUE,byteBuf));
//        socketChannel.pipeline().addLast(new StringDecoder());

    }
    
}